
package com.fricano.java42.swing.dings.tester;

import java.util.List;

import javax.swing.JButton;
import javax.swing.JSlider;

import com.fricano.java42.base.components.helper.Helper_Development;
import com.fricano.java42.base.components.helper.impl.J42JControlPanelCallback;
import com.fricano.java42.base.components.helper.media.impl.J42MultiToneGenerator;

public class MotorolaQuickCall {

    /**
     *   http://www.genave.com/mot_code_table.htm
     *
    Motorola Quick Call 1 - Paging Codes
    Motorola Paging Codes - "Two Plus Two" or Code Type "Y".

    No.
         A Series       B Series       Z Series
         Reed  Freq     Reed  Freq.    Reed  Freq.
    0    CA    358.9    CB    371.5    CZ    346.7
    1    DA    398.1    DB    412.1    DZ    384.6
    2    EA    441.6    EB    457.1    EZ    426.6
    3    FA    489.8    FB    507.0    FZ    473.2
    4    GA    543.3    GB    562.3    GZ    524.8
    5    HA    602.6    HB    623.7    HZ    582.1
    6    JA    668.3    JB    691.8    JZ    645.7
    7    KA    741.3    KB    787.4    KZ    716.7
    8    LA    822.2    LB    851.1    LZ    794.3
    9    MA    912.0    MB    844.1    MZ    881.0
         NA   1011.6    NB   1047.1    NZ    977.2
         PA   1122.1    PB   1161.4    PZ   1084.0



    * @throws Exception
    */

    static int      maxControls = 10;
    static double[] f           = new double[maxControls];

    public static void main(final String[] args) throws Exception {
        //final double[] hertzes = new double[] { 398.1, 412.1, 384.6 };

        //final J42MultiToneGenerator player = new J42MultiToneGenerator_Type02();
        final J42MultiToneGenerator player = J42MultiToneGenerator.getInstance();
        //player.setVolumeLevel(80);

        // http://en.wikipedia.org/wiki/Motorola_Minitor
        //        player.playSynchronous(new double[] { 879.0, 358.6 }, 2000);

        //        player.playSynchronous(new double[] { 589.7, 977 }, 1000);
        //        player.playSynchronous(new double[] { 1 }, 250);
        //        player.playSynchronous(new double[] { 384.6, 716.7 }, 2000);
        //        player.playSynchronous(new double[] { 1 }, 250);
        Helper_Development.getInstance().createJ42JControlPanel(JButton.class, "Play", 1, new J42JControlPanelCallback<JButton, JButton>() {

            @Override
            public void updated(final List<JButton> controls, final JButton control, final int index) {
                try {
                    player.playAsynchronous(f, 2000);
                } catch (final Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void configure(final JButton control, final int index) {
                control.setText("Play");
            }
        });

        Helper_Development.getInstance().createJ42JControlPanel(JSlider.class, "", maxControls, new J42JControlPanelCallback<JSlider, JSlider>() {
            @Override
            public void updated(final List<JSlider> components, final JSlider component, final int index) {
                f[index] = component.getValue();
                System.out.println(f[0] + " " + f[1] + " " + f[2] + " " + f[3]);
                try {
                    player.playAsynchronous(f, 200);
                } catch (final Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

            @Override
            public void configure(final JSlider component, final int index) {
                component.setMinimum(0);
                component.setMaximum(5000);
            }
        });

        //final FFT fft2 = AlgorithmsFactory.getInstance().getFFT(Type.TYPE_1, 10);
        //final com.sun.media.sound.FFT fft3 = new com.sun.media.sound.FFT(0, 0);

        //Thread.sleep(3000);
    }

}
